#include "webenginewidgetmainwindow.h"
#include "ui_webenginewidgetmainwindow.h"

#include <QWebEngineView>

WebEngineWidgetMainWindow::WebEngineWidgetMainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::WebEngineWidgetMainWindow)
{
    ui->setupUi(this);

    auto addItem = [this](QString text) {
        auto url = "https://githubuser0xffff.github.io/Qt-Advanced-Docking-System/doc/user-guide.html" + text;
        auto item = new QListWidgetItem;
        item->setText(text);
        item->setData(Qt::UserRole, url);
        ui->listWidget->addItem(item);
    };

    connect(ui->webview, &QWebEngineView::loadFinished, this, [this](bool b){
        qDebug() << "loadFinished:" << b;
    });

    addItem("#configuration-flags");
    addItem("#setting-configuration-flags");
    addItem("#activetabhasclosebutton");
    addItem("#dockareahasclosebutton");
    addItem("#dockareaclosebuttonclosestab");
    addItem("#opaquesplitterresize");
    addItem("#xmlautoformattingenabled");
    addItem("#xmlcompressionenabled");
    addItem("#tabclosebuttonistoolbutton");
    addItem("#alltabshaveclosebutton");
    addItem("#retaintabsizewhenclosebuttonhidden");
    addItem("#dragpreviewisdynamic");
    addItem("#dragpreviewshowscontentpixmap");
    addItem("#dragpreviewhaswindowframe");
    addItem("#alwaysshowtabs");
    addItem("#dockareahasundockbutton");
    addItem("#dockareahastabsmenubutton");
    addItem("#dockareahidedisabledbuttons");
    addItem("#dockareadynamictabsmenubuttonvisibility");
    addItem("#floatingcontainerhaswidgettitle");
    addItem("#floatingcontainerhaswidgeticon");
    addItem("#hidesinglecentralwidgettitlebar");
    addItem("#focushighlighting");
    addItem("#equalsplitoninsertion");
    addItem("#floatingcontainerforcenativetitlebar-linux-only");
    addItem("#floatingcontainerforceqwidgettitlebar-linux-only");
    addItem("#middlemousebuttonclosestab");
    addItem("#disabletabtexteliding");
    addItem("#showtabtextonlyforactivetab");
    addItem("#doubleclickundockswidget");
    addItem("#auto-hide-dock-widgets");
    addItem("#pinning-auto-hide-widgets-to-a-certain-border");
    addItem("#show--hide-auto-hide-widgets-via-mouse-over");
    addItem("#drag--drop-to-auto-hide");
    addItem("#auto-hide-tab-insertion-order");
    addItem("#auto-hide-tab-sorting");
    addItem("#auto-hide-drag-to-float--dock");
    addItem("#auto-hide-context-menu");
    addItem("#adding-auto-hide-widgets");
    addItem("#auto-hide-configuration-flags");
    addItem("#setting-auto-hide-flags");
    addItem("#autohidefeatureenabled");
    addItem("#dockareahasautohidebutton");
    addItem("#autohidebuttontogglesarea");
    addItem("#autohidebuttoncheckable");
    addItem("#autohidesidebarsicononly");
    addItem("#autohideshowonmouseover");
    addItem("#autohideclosebuttoncollapsesdock");
    addItem("#autohidehasclosebutton");
    addItem("#autohidehasminimizebutton");
    addItem("#autohideopenondraghover");
    addItem("#autohidecloseonoutsidemouseclick");
    addItem("#dockwidget-feature-flags");
    addItem("#dockwidgetclosable");
    addItem("#dockwidgetmovable");
    addItem("#dockwidgetfloatable");
    addItem("#dockwidgetdeleteonclose");
    addItem("#customclosehandling");
    addItem("#dockwidgetfocusable");
    addItem("#dockwidgetforceclosewitharea");
    addItem("#notab");
    addItem("#deletecontentonclose");
    addItem("#central-widget");
    addItem("#empty-dock-area");
    addItem("#custom-close-handling");
    addItem("#globally-lock-docking-features");
    addItem("#dock-widget-size--minimum-size-handling");
    addItem("#styling");
    addItem("#disabling-the-internal-style-sheet");
    addItem("#using-ads-on-linux");
    addItem("#supported-distributions");
    addItem("#requirements");
    addItem("#manjaro-xfce-2501-and-xubuntu-24042-issues");
    addItem("#opengl--ads");
}

WebEngineWidgetMainWindow::~WebEngineWidgetMainWindow()
{
    delete ui;
}

void WebEngineWidgetMainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if (!current) return;

    ui->webview->load(current->data(Qt::UserRole).toString());
}

